﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Reflection;

namespace TestApplication
{
    public partial class Form2 : zytech.common.baseform.sys.MainFrame
    {
        DataSet ds1;
        public Form2()
        {
            SqlConnStr = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
            InitializeComponent();
        }
        public Form2(string n, string p)
            : base(n, p)
        {
            SqlConnStr = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            if (name == "admin")        //管理员账号 则加载所有菜单
                SetAdminMenu();
            else
                SetOtherMenu(name);     //其他按照权限加载
            timer1.Enabled = true;

            /*this.pictureBox1.Image = TestApplication.Properties.Resources.logo;
            toolStripStatusLabel1.Image = TestApplication.Properties.Resources.home;
            toolStripStatusLabel4.Image = TestApplication.Properties.Resources.butterFly;
            toolStripStatusLabel3.Image = TestApplication.Properties.Resources.window;*/
            toolStripStatusLabel4.Text = "当前操作员:" + Login.name + "        ";
            toolStripStatusLabel1.Text = "当前使用单位:金华正元计算机";
            toolStripStatusLabel3.Text = "当前时间:" + DateTime.Now.ToString("yyyy年m月d日 hh:mm:ss") + "(" + zytech.common.Functions.ConvertDateTime(DateTime.Now) + ")";
        }
        //重新登陆
        protected override void ReLoginToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form fm = new Login();
            fm.Show();
            this.Hide();
        }
        //修改密码
        protected override void PwdEditToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*Form fm = new PwdModify();
            fm.MdiParent = this;
            fm.Show();*/
            Form fm1 = new PwdModify();
            ShowMdiWindow(fm1, this);
        }
        //关于
        protected override void AboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 fm1 = new Form1();
            ShowMdiWindow(fm1, this);
        }
        //点击节点加载其子节点（其他人员）
        protected override void tsm_other_Click(object sender, EventArgs e)
        {
            base.tsm_other_Click(sender, e);
            string sql1 = "Select * from sys_menu";
            ds1 = zytech.common.Functions.getDataset(sql1, SqlConnStr);
            //得到当前菜单项的Tag 属性，它表示菜单的ID
            DataRow[] rows = ds1.Tables[0].Select("menu_id=" + (sender as ToolStripMenuItem).Tag);
            //得到数据库中窗体的名称
            string formName = rows[0]["FormName"].ToString();//Formname为命名空间.窗体名
            string str = System.Windows.Forms.Application.StartupPath;
            //以下是通过反射动态实例化窗体对象
            Assembly assembly = Assembly.GetExecutingAssembly();
            Type t = assembly.GetType(formName);
            object obj = Activator.CreateInstance(t);
            Form frm = (Form)obj;
            frm.MdiParent = this;       //将窗体设置为main窗体的子窗体
            frm.Show();
        }
        protected override void tsm_admin_Click(object sender, EventArgs e)
        {
            base.tsm_admin_Click(sender, e);
            string sql1 = "Select * from sys_menu";
            ds1 = zytech.common.Functions.getDataset(sql1, SqlConnStr);
            //得到当前菜单项的Tag 属性，它表示菜单的ID
            DataRow[] rows = ds1.Tables[0].Select("menu_id=" + (sender as ToolStripMenuItem).Tag);
            //得到数据库中窗体的名称
            string formName = rows[0]["FormName"].ToString();//Formname为命名空间.窗体名
            string str = System.Windows.Forms.Application.StartupPath;
            //以下是通过反射动态实例化窗体对象
            Assembly assembly = Assembly.GetExecutingAssembly();
            Type t = assembly.GetType(formName);
            object obj = Activator.CreateInstance(t);
            Form frm = (Form)obj;
            frm.MdiParent = this;       //将窗体设置为main窗体的子窗体
            frm.Show();
        }
        protected override void SetAdminMenu()
        {
            base.SetAdminMenu();
        }
        protected override void SetOtherMenu(string str)
        {
            base.SetOtherMenu(str);
        }
        protected override void GetAdminChild(ToolStripMenuItem tsmi)
        {
            base.GetAdminChild(tsmi);
        }
        protected override void GetOtherChild(ToolStripMenuItem tsmi)
        {
            base.GetOtherChild(tsmi);
        }
        
    }
}
